<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>作用域插槽案例</title>
  </head>
  <body>
    <div id="app">
      <cpn></cpn>
      <cpn>
        <!-- 目的是获取子组件中的pLanguages Vue 2.5.X及以下必须使用template -->
        <template slot-scope="slot">
          <!--<span v-for="item in slot.data">{{item}} | </span>-->
          <span>{{slot.data.join('  |  ')}}</span>
        </template>
      </cpn>
    </div>

    <template id="cpn">
      <div>
        <slot :data="pLanguages">
          <ul>
            <li v-for="item in pLanguages">{{item}}</li>
          </ul>
        </slot>
      </div>
    </template>

    <script src="../js/vue.js"></script>
    <script>
      const cpn = {
        template: '#cpn',
        data() {
          return {
            pLanguages: ['JavaScript', 'Python', 'Swift', 'Go', 'C++', 'Java', 'PHP']
          }
        }
      }

      const app = new Vue({
        el: '#app',
        data: {
          message: 'Demo',

        },
        methods: {

        },
        components: {
          cpn
        }
      })
    </script>
  </body>
</html>